package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.HistoryPointData;
import com.ruoyi.system.mapper.HistoryPointDataMapper;
import com.ruoyi.system.service.HistoryPointDataService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 历史实时数据(HistoryPointData)表服务实现类
 *
 * @author makejava
 * @since 2023-05-09 11:16:07
 */
@Service("historyPointDataService")
public class HistoryPointDataServiceImpl implements HistoryPointDataService {
    @Resource
    private HistoryPointDataMapper historyPointDataMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public HistoryPointData queryById(Integer id) {
        return this.historyPointDataMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param historyPointData 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<HistoryPointData> queryByPage(HistoryPointData historyPointData, PageRequest pageRequest) {
        long total = this.historyPointDataMapper.count(historyPointData);
        return new PageImpl<>(this.historyPointDataMapper.queryAllByLimit(historyPointData, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param historyPointData 实例对象
     * @return 实例对象
     */
    @Override
    public HistoryPointData insert(HistoryPointData historyPointData) {
        this.historyPointDataMapper.insert(historyPointData);
        return historyPointData;
    }

    /**
     * 修改数据
     *
     * @param historyPointData 实例对象
     * @return 实例对象
     */
    @Override
    public HistoryPointData update(HistoryPointData historyPointData) {
        this.historyPointDataMapper.update(historyPointData);
        return this.queryById(historyPointData.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.historyPointDataMapper.deleteById(id) > 0;
    }
}
